package com.myHospital.controller;

import com.alibaba.fastjson.JSON;
import com.myHospital.biz.HospitalBiz;
import com.myHospital.biz.UserBiz;
import com.myHospital.biz.UserRoleBiz;
import com.myHospital.entity.Hospital;
import com.myHospital.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AdminController {
    @Autowired
    private UserBiz userBiz;
    @Autowired
    private UserRoleBiz userRoleBiz;
    @Autowired
    private HospitalBiz hospitalBiz;
    @RequestMapping("admin/index")
    public String index() {
        return "admin/index";
    }

    @RequestMapping("/admin/userlist")
    public String userlist(String name, String phone, String site, Integer page, Model model) {
        System.out.println(name);
        if(page==null) {
            page = 1;
        }
        int pageSize=5;
        List<User> userList=userBiz.SearchUser(name,phone,site,(page-1)*pageSize,pageSize);
        model.addAttribute("userList",userList);
        return "admin/userlist";
    }
    @RequestMapping("admin/userInformation")
    public String userInformation(int id,Model model){
        User user=userBiz.getById(id);
        model.addAttribute("user",user);
        return  "admin/userInformation";
    }
    @RequestMapping("admin/addBlacklist")
    public String addBlacklist(int id){
        userRoleBiz.addBlacklist(id);
        return "redirect:/admin/userlist";
    }
    @RequestMapping("admin/blacklist")
    public String getBlacklist(Model model){
        List<User> blacklist =userRoleBiz.getBlacklist();
        model.addAttribute("blacklist",blacklist);
        return "admin/blacklist";
    }
    @RequestMapping("admin/deleteBlacklist")
    public String deleteBlacklist(int id){
        userRoleBiz.deleteBlacklist(id);
        return "redirect:/admin/blacklist";
    }
    @RequestMapping("admin/adminlist")
    public String adminlist(){
        return "admin/adminlist";
    }
    @RequestMapping("admin/hospitallist")
    public String hospitallist(Model model){
        List<Hospital> hospitals =hospitalBiz.getAll();
        model.addAttribute("hospitals",hospitals);
        return "admin/hospitallist";
    }
    @RequestMapping("admin/hospitalInformation")
    public String hospitalInformation(int id,Model model){
        Hospital hospital=hospitalBiz.getById(id);
        model.addAttribute("hospital",hospital);
        return "admin/hospitalInformation";
    }
}
